<template>
  <div class="app-container">
    <h2 style="text-align: center">#訂單管理頁面#</h2>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="" prop="driverPhone">
        <el-input
          v-model="queryParams.orderNumber"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="" prop="passengerPhone">
        <el-input
          v-model="queryParams.passengerPhone"
          placeholder="请输入乘客电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="" prop="plateNumber">
        <el-input
          v-model="queryParams.plateNumber"
          placeholder="请输入车牌号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="订单状态" prop="driverPhone">
        <el-select v-model="queryParams.status" placeholder="全部支付方式">
          <el-option label="创建订单" value="0"></el-option>
          <el-option label="司机接单" value="1"></el-option>
          <el-option label="去接乘客" value="2"></el-option>
          <el-option label="司机到达乘客起点" value="3"></el-option>
          <el-option label="乘客上车,司机开始行程" value="4"></el-option>
          <el-option label="到达目的地,行程结束" value="5"></el-option>
          <el-option label="发起收款-0" value="6"></el-option>
          <el-option label="已完成-1" value="7"></el-option>
          <el-option label="订单取消-0或1" value="8"></el-option>
          <el-option label="待派订单" value="9"></el-option>
        </el-select>
      </el-form-item>


      <el-form-item label="" prop="driverPhone">
        <el-input
          v-model="queryParams.driverPhone"
          placeholder="请输入司机电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item label="服务类型" prop="driverPhone">
        <el-select v-model="queryParams.serviceType" placeholder="订单类型">
          <el-option label="实时单" value="1"></el-option>
          <el-option label="预约单" value="2"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="支付方式" prop="driverPhone">
        <el-select v-model="queryParams.payType" placeholder="全部支付方式">
          <el-option label="余额" value="1"></el-option>
          <el-option label="微信" value="2"></el-option>
          <el-option label="支付宝" value="3"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="支付状态" prop="driverPhone">
        <el-select v-model="queryParams.payType" placeholder="请选择支付状态">
          <el-option label="未支付" value="0"></el-option>
          <el-option label="已支付" value="1"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="" prop="startTime">
        <el-date-picker clearable
          v-model="queryParams.startTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择乘客下单时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="" prop="driverArrivedTime">
        <el-date-picker clearable
          v-model="queryParams.driverArrivedTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择司机到达时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="" prop="receivePassengerTime">
        <el-date-picker clearable
          v-model="queryParams.receivePassengerTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择接到乘客时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="" prop="timeInCar">
        <el-date-picker clearable
          v-model="queryParams.timeInCar"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择乘客用车时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:order:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单号" align="center" prop="orderNumber" />
      <el-table-column label="乘客id" align="center" prop="passengerInfoId" />
      <el-table-column label="乘客电话" align="center" prop="passengerPhone" />
      <el-table-column label="司机id" align="center" prop="driverId" />
      <el-table-column label="司机姓名" align="center" prop="driverName" />
      <el-table-column label="城市编码" align="center" prop="cityCode" />
<!--      <el-table-column label="司机状态" align="center" prop="driverStatus">-->
<!--        <template slot-scope="scope">-->
<!--          <span v-if="scope.row.driverStatus === 1">-->
<!--            <span class="el-tag el-tag&#45;&#45;primary">未上线</span>-->
<!--          </span>-->
<!--          <span v-else-if="scope.row.driverStatus === 2">-->
<!--            <span class="el-tag el-tag&#45;&#45;success">已上线</span>-->
<!--          </span>-->
<!--          <span v-else-if="scope.row.driverStatus === 3">-->
<!--            <span class="el-tag el-tag&#45;&#45;success">运送乘客中</span>-->
<!--          </span>-->
<!--          <span v-else-if="scope.row.driverStatus === 4">-->
<!--            <span class="el-tag el-tag&#45;&#45;success">空闲</span>-->
<!--          </span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="司机电话" align="center" prop="driverPhone" />
      <el-table-column label="车辆id" align="center" prop="carId" />
      <el-table-column label="车牌号" align="center" prop="plateNumber" />
      <el-table-column label="起点名称" align="center" prop="startAddress" />
      <el-table-column label="终点地址名称" align="center" prop="endAddress" />
      <el-table-column label="叫车订单类型" align="center" prop="serviceType">
        <template slot-scope="scope">
          <span v-if="scope.row.serviceType === 0">
            <span class="el-tag el-tag--primary">实时</span>
          </span>
          <span v-else-if="scope.row.serviceType === 1">
            <span class="el-tag el-tag--success">预约</span>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status === 0">
            <span class="el-tag el-tag--primary">订单开始</span>
          </span>
          <span v-else-if="scope.row.status === 1">
            <span class="el-tag el-tag--success">司机接单</span>
          </span>
          <span v-if="scope.row.status === 2">
            <span class="el-tag el-tag--primary">司机到达乘客起点</span>
          </span>
          <span v-if="scope.row.status === 3">
            <span class="el-tag el-tag--primary">乘客上车,司机开始行程</span>
          </span>
          <span v-if="scope.row.status === 4">
            <span class="el-tag el-tag--primary">到达目的地,行程结束,未支付</span>
          </span>
          <span v-if="scope.row.status === 5">
            <span class="el-tag el-tag--primary">发起收款</span>
          </span>
          <span v-if="scope.row.status === 6">
            <span class="el-tag el-tag--primary">已支付</span>
          </span>
          <span v-if="scope.row.status === 7">
            <span class="el-tag el-tag--primary">订单取消</span>
          </span>
          <span v-if="scope.row.status === 10">
            <span class="el-tag el-tag--primary">去接乘客</span>
          </span>
          <span v-else-if="scope.row.status === 11">待派订单</span>
        </template>
      </el-table-column>
      <el-table-column label="乘客是否评价" align="center" prop="isEvaluate">
        <template slot-scope="scope">
          <span v-if="scope.row.isEvaluate === 0">
            <span class="el-tag el-tag--primary">未评价</span>
          </span>
          <span v-else-if="scope.row.isEvaluate === 1">
            <span class="el-tag el-tag--success">已评价</span>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="支付方式" align="center" prop="payType">
        <template slot-scope="scope">
          <span v-if="scope.row.payType === 1">
            <span class="el-tag el-tag--primary">余额</span>
          </span>
          <span v-else-if="scope.row.payType === 2">
            <span class="el-tag el-tag--success">微信</span>
          </span>
          <span v-else-if="scope.row.payType === 3">支付宝</span>
        </template>
      </el-table-column>

      <el-table-column label="是否已支付" align="center" prop="payType">
        <template slot-scope="scope">
          <span v-if="scope.row.isPaid === 1">
            <span class="el-tag el-tag--primary">已支付</span>
          </span>
          <span v-else-if="scope.row.isPaid === 0">
            <span class="el-tag el-tag--success">未支付</span>
          </span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:order:edit']"
          >查看订单详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:order:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 回显对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单号" prop="passengerInfoId">
          <el-input v-model="form.orderNumber" placeholder="" disabled/>
        </el-form-item>

        <el-form-item label="城市" prop="carId">
          <el-input v-model="form.carId" placeholder="" disabled/>
        </el-form-item>

        <el-form-item label="服务类型" prop="carId">
          <el-input v-model="form.serviceType" placeholder="" disabled />
        </el-form-item>

        <el-form-item label="车辆级别" prop="carId">
          <el-input v-model="form.carId" placeholder="" disabled/>
        </el-form-item>

        <el-form-item label="订单状态" prop="carId">
          <el-input v-model="form.carId" placeholder="" disabled/>
        </el-form-item>

        <el-form-item label="上车起点" prop="startAddress">
          <el-input v-model="form.startAddress" placeholder="" disabled/>
        </el-form-item>

        <el-form-item label="下车地点" prop="endAddress">
          <el-input v-model="form.endAddress" placeholder="" disabled/>
        </el-form-item>

        <el-form-item label="订单金额" prop="startAddress">
          <el-input v-model="form.orderMoney" placeholder="" disabled/>
        </el-form-item>

        <el-form-item label="服务时长" prop="endAddress">
          <el-input v-model="form.endAddress" placeholder="" disabled/>
        </el-form-item>

        <el-form-item label="服务里程(公里)" prop="endAddress">
          <el-input v-model="form.endAddress" placeholder="" disabled/>
        </el-form-item>

        <el-form-item label="下单来源" prop="endAddress">
          <el-input v-model="form.endAddress" placeholder="" disabled/>
        </el-form-item>

        <el-form-item label="支付类型" prop="endAddress">
<!--          <el-input v-model="" placeholder="">-->
<!--          </el-input>-->
          <el-select v-model="form.payType" placeholder="全部支付方式" disabled>
            <el-option label="余额" :value="1"></el-option>
            <el-option label="微信" :value="2"></el-option>
            <el-option label="支付宝" :value="3"></el-option>
          </el-select>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder, listOrderNumber } from '@/api/system/order'

export default {
  name: "Order",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        orderNumber:'',
        passengerPhone:'',
        plateNumber:'',
        driverPhone:'',
        status:'',
        payType:'',
        serviceType:'',
        startTime:'',
        createTime:'',
        pageNum:1,
        pageSize:10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        console.log(response);
        this.orderList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderNumber: null,
        passengerInfoId: null,
        passengerPhone: null,
        driverId: null,
        driverStatus: null,
        driverPhone: null,
        carId: null,
        plateNumber: null,
        userLongitude: null,
        userLatitude: null,
        startLongitude: null,
        startLatitude: null,
        startAddress: null,
        endAddress: null,
        startTime: null,
        orderStartTime: null,
        endLongitude: null,
        endLatitude: null,
        driverGrabTime: null,
        driverStartTime: null,
        driverArrivedTime: null,
        pickUpPassengerLongitude: null,
        pickUpPassengerLatitude: null,
        pickUpPassengerAddress: null,
        receivePassengerTime: null,
        receivePassengerLongitude: null,
        receivePassengerLatitude: null,
        passengerGetoffTime: null,
        passengerGetoffLongitude: null,
        passengerGetoffLatitude: null,
        serviceType: null,
        status: null,
        isEvaluate: null,
        payType: null,
        isPaid: null,
        isCancel: null,
        isAdjust: null,
        isDissent: null,
        createTime: null,
        updateTime: null,
        timeInCar: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderNumber)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      listOrderNumber(row).then(response => {
        console.log(response)
        this.form = response.data;
        this.open = true;
        this.title = "查看订单详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
              this.open = false;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderNumbers = row.orderNumber || this.ids;
      this.$modal.confirm('是否确认删除订单编号为"' + orderNumbers + '"的数据项？').then(function() {
        return delOrder(orderNumbers);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
